Git部分常用命令[转]

git

初始化本地git仓库(创建新仓库)

1
git init

配置用户名

1
git config --global user.name "xxx"

配置邮件

1
git config --global user.email "xxx@xxx.com"

git status等命令自动着色

1
2
3
4
5
6
7
8
9
10
11
12
13
14

git config --global color.ui true
git config --global color.status auto
git config --global color.diff auto
git config --global color.branch auto
git config --global color.interactive auto

```


## clone远程仓库

```js
git clone git+ssh://git@192.168.53.168/VT.git

查看当前版本状态(是否修改)

1
git status

添加xxx文件至index

1
2
3
4
5
6
    git add xxx
```

## 增加当前子目录下所有更改过的文件至index
```js
git add .

提交

1
git commit --amend -m 'xxx'

将add和commit合为一步

1
git commit -am 'xxx'

删除index中的文件

1
git rm xxx

递归删除

1
git rm -r *

显示提交日志

1
git log

显示1行日志 -n为n行

1
2
git log -1                                                
git log -5

显示提交日志及相关变动文件

1
2
git log --stat                                            
git log -p -m

显示某个提交的详细内容

1
git show dfb02e6e4f2f7b573337763e5c0013802e392818

比较与上一个版本的差异

1
git diff HEAD^

比较与HEAD版本lib目录的差异

1
git diff HEAD -- ./lib

比较远程分支master上有本地分支master上没有的

1
git diff origin/master..master

只显示差异的文件,不显示具体内容

1
git diff origin/master..master --stat

增加远程定义(用于push/pull/fetch)

1
git remote add origin git+ssh://git@192.168.53.168/VT.git

显示本地分支

1
git branch

显示所有分支

1
git branch -a

显示所有原创分支

1
git branch -r

显示所有已合并到当前分支的分支

1
git branch --merged

显示所有未合并到当前分支的分支

1
git branch --no-merged

删除远程仓库的hotfixes/BJVEP933分支

1
git push origin :hotfixes/BJVEP933

重命名文件README为README2

1
git mv README README2